Unity 粒子ParticleSystem正确的关闭方式 您所在的位置:网站首页 unity particlesystem粒子点击播放 Unity 粒子ParticleSystem正确的关闭方式

Unity 粒子ParticleSystem正确的关闭方式

2024-07-04 10:02| 来源: 网络整理| 查看: 265

Unity 粒子ParticleSystem正确的关闭方式 using System; using System.Collections; using UnityEngine; using Random = UnityEngine.Random; public class ParticleSystemDestroyer : MonoBehaviour { //允许一个粒子系统在指定的时间存在, //然后关闭发射,并等待所有粒子到期 //破坏前的游戏对象 public float minDuration = 8; public float maxDuration = 10; private float m_MaxLifetime; private bool m_EarlyStop; private IEnumerator Start() { var systems = GetComponentsInChildren(); // find out the maximum lifetime of any particles in this effect foreach (var system in systems) { m_MaxLifetime = Mathf.Max(system.main.startLifetime.constant, m_MaxLifetime); } // wait for random duration float stopTime = Time.time + Random.Range(minDuration, maxDuration); while (Time.time < stopTime || m_EarlyStop) { yield return null; } Debug.Log("stopping " + name); // turn off emission foreach (var system in systems) { var emission = system.emission; emission.enabled = false; } BroadcastMessage("Extinguish", SendMessageOptions.DontRequireReceiver); // wait for any remaining particles to expire yield return new WaitForSeconds(m_MaxLifetime); Destroy(gameObject); } public void Stop() { // stops the particle system early m_EarlyStop = true; } }

这里写图片描述

我是李本心明

首先谢谢大家的支持,其次如果你碰到什么其他问题的话,欢迎来 我自己的一个 讨论群559666429来(扫扫下面二维码或者点击群链接 Unity3D[ 交流] ),大家一起找答案,共同进步。

由于工作生活太忙了,对于大家的帮助时间已经没有之前那么充裕了。如果有志同道合的朋友,可以接受无偿的帮助别人,可以加我QQ单独联系我,一块经营一下。

在这里插入图片描述



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有